/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  发送聊天信息
	/// module : structs
	/// </summary>
	public class CChatPOD : IPOD 
    {
        public readonly static Func<CChatPOD> FACTORY = () => new CChatPOD();
		public static Func<CChatPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 频道
        /// </summary>
		public ChatChannel channel;
		/// <summary>
        /// 类型
        /// </summary>
		public ChatType type;
		/// <summary>
        /// 目标：例如：私聊人的名称
        /// </summary>
		public string target;
		/// <summary>
        /// 内容：
        /// </summary>
		public string content;
		
		
		
		/*-- constructors --*/
		public CChatPOD() {}
		public CChatPOD(ChatChannel channel, ChatType type, string target, string content) {
			this.channel = channel;
			this.type = type;
			this.target = target;
			this.content = content;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_byte((sbyte)channel);
            _out.Write_byte((sbyte)type);
            _out.Write_string(target);
            _out.Write_string(content);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            channel = (ChatChannel)_in.Read_byte();
            if(!_in.HasRemaining()) return;
            type = (ChatType)_in.Read_byte();
            if(!_in.HasRemaining()) return;
            target = _in.Read_string();
            if(!_in.HasRemaining()) return;
            content = _in.Read_string();
        }
		
		public CChatPOD Clone() {
            CChatPOD o = DynamicFactory();
            o.channel = channel;
            o.type = type;
            o.target = target;
            o.content = content;
            return o;
        }
        
        public void Clear() {
            channel = default;
            type = default;
            target = default;
            content = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "CChatPOD [";
			str += "channel=";
			str += channel;
			str += ", type=";
			str += type;
			str += ", target=";
			str += target;
			str += ", content=";
			str += content;
			str += "]";
			return str;
		}
		
	}
}